package com.lmk.mkcc.service.impl;

import com.lmk.mkcc.service.ICommonService;
import com.lmk.mkcc.util.StrUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class CommonServiceImpl implements ICommonService {

    private String redisOrderToken = "orderToken:%s:%s";

    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;

    @Override
    public String getcreateToken(String courseIds) {
        // 随机生成一个token
        String token = StrUtils.getComplexRandomString(10);
        // 设置一个key将token保存到redis中
        Long loginId = 3L;
        String orserkey = String.format(redisOrderToken, loginId, courseIds);
        redisTemplate.opsForValue().set(orserkey,token,5, TimeUnit.MINUTES);
        return token;
    }
}
